//
//  YDAHomeTopView.m
//  siyanone
//
//  Created by LK-IOS on 2018/3/23.
//  Copyright © 2018年 LK-News. All rights reserved.
//

#import "YDAHomeTopView.h"
#import "DRJCycleScrollView.h"
#import "YDHomeMarketView.h"

@interface YDAHomeTopView()<DRJCycleScrollViewDelegate , SYHomeMarketViewDelegate>
//轮播图
@property (nonatomic , weak) DRJCycleScrollView *cycleView;
//大盘走势view
@property (nonatomic , weak) YDHomeMarketView *marketView;


@end



@implementation YDAHomeTopView

-(void)setCarsoulImageUrlArray:(NSArray *)carsoulImageUrlArray
{
    _carsoulImageUrlArray = carsoulImageUrlArray;
    //刷新轮播图
    self.cycleView.imageURLStringsGroup = carsoulImageUrlArray;
}

-(void)setImageTitleArray:(NSArray *)imageTitleArray
{
    _imageTitleArray = imageTitleArray;
    self.cycleView.titlesGroup = imageTitleArray;
}

-(void)setMarketModelArray:(NSArray *)marketModelArray
{
    _marketModelArray = marketModelArray;
    
    self.marketView.marketModelArray = marketModelArray;
}

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = NumberColor(247, 247, 247);
        
        [self cycleView];
        
        [self marketView];
    }
    return self;
}
+(instancetype)homeTopViewWithCarsoulImageUrlArray:(NSArray *)carsoulImageUrlArray ImageTitleArray:(NSArray *)imageTitleArray MarketModelArray:(NSArray *)marketModelArray
{
    YDAHomeTopView *topView = [[self alloc] init];
    
    topView.carsoulImageUrlArray = carsoulImageUrlArray;
    topView.imageTitleArray = imageTitleArray;
    topView.marketModelArray = marketModelArray;
    
    return topView;
}

/*********轮播视图***********/
-(DRJCycleScrollView *)cycleView
{
    if (_cycleView == nil) {
        CGFloat cycleViewH;
        if (isPhoneX) {
            cycleViewH = rateX812(210);
        }else{
            cycleViewH = rate750(210);
        }
        DRJCycleScrollView *cycleView = [DRJCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, LKScreenW, cycleViewH) imageURLStringsGroup:self.carsoulImageUrlArray];
        [self addSubview:cycleView];
        cycleView.backgroundColor = [UIColor whiteColor];
        cycleView.titlesGroup= self.imageTitleArray;
        cycleView.placeholderImage =[UIImage imageNamed:@"banner-bg"];
        cycleView.delegate = self;
        cycleView.showPageControl = NO;
        cycleView.titleLabelTextFont=[UIFont systemFontOfSize:font16ScreenWRate * LKScreenW];
        cycleView.titleLabelHeight = 30;
        cycleView.width = LKScreenW;
        cycleView.height = cycleViewH;
        _cycleView = cycleView;
    }
    return _cycleView;
}
/*********DRJCycleScrollViewDelegate********/
-(void)cycleScrollView:(DRJCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    if ([_delegate respondsToSelector:@selector(homeTopView:didSelectedViewType:viewIndex:)]) {
        [_delegate homeTopView:self didSelectedViewType:SYAHomeTopViewStyleCarsoul viewIndex:index];
    }
}

/*********大盘视图***********/
-(YDHomeMarketView *)marketView
{
    if (_marketView == nil) {
        CGFloat marketH;
        if (isPhoneX) {
            marketH = rateX812(80);
        }else{
            marketH = rate750(80);
        }
        YDHomeMarketView *marketView = [YDHomeMarketView homeMarketViewMarketModelArray:self.marketModelArray];
        [self addSubview:marketView];
        marketView.delegate = self;
        marketView.frame = CGRectMake(0, CGRectGetMaxY(_cycleView.frame), LKScreenW, marketH);
        _marketView = marketView;
    }
    return _marketView;
}
/**********PZHomeMarketViewDelegate*************/
-(void)homeMarketView:(YDHomeMarketView *)homeMarketView didSelectItemAtIndex:(NSInteger)index
{
    if ([_delegate respondsToSelector:@selector(homeTopView:didSelectedViewType:viewIndex:)]) {
        [_delegate homeTopView:self didSelectedViewType:SYAHomeTopViewStyleMarket viewIndex:index];
    }
}

@end
